from django.db import models
from apps.goods.models import Goods
from apps.user.models import User

class Comment(models.Model):
    score_detail = [(0, '未评价'), (1, '一星'), (2, '二星'), (3, '三星'), (4, '四星'), (5, '五星')]
    comment_id = models.AutoField(primary_key=True, unique=True, verbose_name="评论ID")
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='comment')
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, related_name='comment')
    score = models.IntegerField(null=False, default=0, choices=score_detail, verbose_name="评分")
    content = models.TextField(verbose_name="评论内容")
    comment_time = models.DateTimeField(auto_now_add=True, verbose_name='评论时间')

    def __str__(self):
        return f'{self.user.name} - {self.content[:5]}'

    class Meta:
        db_table = 'comment'